package org.tlipoca.smcommentimage.controller;

import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import lombok.extern.slf4j.Slf4j;
import org.genntii.smcommon.result.Result;
import org.genntii.smdomain.dto.CommentImageDTO;
import org.genntii.smdomain.entity.CommentImage;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;
import org.tlipoca.smcommentimage.service.CommentImageService;

import java.util.ArrayList;
import java.util.HashMap;

@Tag(name = "评论图片")
@Slf4j
@RestController
@RequestMapping("/comment_image")
public class CommentImageController {

    @Autowired
    private CommentImageService commentImageService;

    @Operation(summary = "根据评论ID列表获取评论图片")
    @PostMapping("/comment")
    public Result<HashMap<Long, ArrayList<CommentImage>>> getCommentImageGroupByCommentIdList(@RequestBody ArrayList<Long> commentIds) {
        System.out.println(commentIds);
        return Result.success(commentImageService.getCommentImageGroupByCommentIdListService(commentIds));
    }

    @Deprecated
    @Operation(summary = "新增评论图片")
    @PostMapping
    Result addCommentImage(@RequestBody ArrayList<CommentImageDTO> commentImageDTOList, ArrayList<MultipartFile> files) {
        commentImageService.addCommentImageService(commentImageDTOList);
        return Result.success();
    }

    @Operation(summary = "根据评论ID删除评论图片")
    @DeleteMapping("/delete/{commentId}")
    Result deleteCommentImageByCommentId(@PathVariable Long commentId) {
        commentImageService.deleteCommentImageByCommentIdService(commentId);
        return Result.success();
    }

}
